
import '../../wonders/router/router.dart';
import 'package:flutter/material.dart';
import './route_handlers.dart';
import '../../demo/data_source/data.dart';
import '../../demo/ui_demo08.dart';
import '../../demo/ui_demo.dart';
import '../../demo/index.dart';
class Routes {
  static String root = "/";

  static void configureRoutes(Router router) async {
    router.notFoundHandler = new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      print("ROUTE WAS NOT FOUND !!!");
    });
    router.define(root, handler: rootHandler);
    //ui_demo08 use
    router.define("/demo/all", handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
          return DemoNavigation();
        }));
    //ui_demo08 use
    router.define("/demo/display", handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
          String param=params["param"].first;
          List<String> _list=[];
          if(param.isNotEmpty){
            _list=param.split(",");
          }
          List<Demo> displayDemos=[];
          _list.forEach((val){
            displayDemos.add(demos[int.parse(val)-1]);
          });
          return DemoDisplay(displayDemos);
        }));
    //ui_demo08 use
    router.define("/about", handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
          return SecondPage("about",Icon(Icons.location_on) );
        }));
    router.define("/source", handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
          String source=params["source"].first;
          sources.forEach((key,value){
            if(key.indexOf(source)>=0)
              source=value;
          });
          return ResourceWidget(params["title"].first,source);
        }));

    await  Stream.fromIterable(demos).listen((demo){
      router.define("/demo${demos.indexOf(demo)+1}", handler: Handler(handlerFunc: (
          BuildContext context, Map<String, List<String>> parameters){
        return demo;
      }));
    });
  }
}
